!function() {
    var t, a = require("../../05BFE3A3C6098CCF63D98BA434E9C3F4.js"), e = a(require("../../E2BD7757C6098CCF84DB1F50F2D9C3F4.js")), i = a(require("../../1361F626C6098CCF75079E21B079C3F4.js")), s = a(require("../../17D380B5C6098CCF71B5E8B28E7AC3F4.js")), o = a(require("../../9D53CC23C6098CCFFB35A4246909C3F4.js"));
    function n(t, a) {
        var e = Object.keys(t);
        if (Object.getOwnPropertySymbols) {
            var i = Object.getOwnPropertySymbols(t);
            a && (i = i.filter(function(a) {
                return Object.getOwnPropertyDescriptor(t, a).enumerable;
            })), e.push.apply(e, i);
        }
        return e;
    }
    function l(t) {
        for (var a = 1; a < arguments.length; a++) {
            var i = null != arguments[a] ? arguments[a] : {};
            a % 2 ? n(Object(i), !0).forEach(function(a) {
                (0, e.default)(t, a, i[a]);
            }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(i)) : n(Object(i)).forEach(function(a) {
                Object.defineProperty(t, a, Object.getOwnPropertyDescriptor(i, a));
            });
        }
        return t;
    }
    var r = getApp();
    Page({
        data: (t = {
            didShow: !1,
            isTouchScale: !1,
            makePosterImage: !1,
            festivalSrc: "../../images/tm.jpg",
            oldx: 0,
            oldy: 0,
            startx: 0,
            starty: 0,
            initRotate: 0,
            rotate: 0,
            loading: !1,
            callback: null,
            logoPath: null,
            currentFestival: "圣诞",
            userInfo: {},
            olduserInfo: {},
            hasScale: !1,
            hasRotate: !1,
            hasUserInfo: !1,
            isOpenSetting: !1,
            canIUse: wx.canIUse("button.open-type.getUserInfo"),
            festivalCenterX: 0,
            festivalCenterY: 0,
            festivalLeft: 120,
            festivalTop: 120,
            offsetx: 0,
            offsety: 0,
            festivalSize: 80,
            festivalIndex: 0,
            festivalImageIndex: 0,
            TabCur: 0,
            scrollLeft: 0,
            bg: "",
            selClass: "",
            selId: -1,
            lock: "",
            lock_info: "",
            isLogo: !1,
            isSrc: !1
        }, (0, e.default)(t, "scrollLeft", 0), (0, e.default)(t, "showtab", 0), (0, e.default)(t, "fontcolor", ""), 
        (0, e.default)(t, "imgData", []), (0, e.default)(t, "currentTab", ""), (0, e.default)(t, "scrollHeight", ""), 
        (0, e.default)(t, "CustomBar", ""), (0, e.default)(t, "bgPic", null), (0, e.default)(t, "imgList", []), 
        (0, e.default)(t, "currentHatId", ""), (0, e.default)(t, "isLogin", !1), (0, e.default)(t, "logoImg", ""), 
        (0, e.default)(t, "yidong", !1), (0, e.default)(t, "modalName", !1), (0, e.default)(t, "tabnav", {
            tabnum: 5,
            tabitem: []
        }), (0, e.default)(t, "productList", []), (0, e.default)(t, "bgArr", []), (0, e.default)(t, "typeArr", []), 
        (0, e.default)(t, "imgArrList", []), (0, e.default)(t, "page", 1), (0, e.default)(t, "loadingDH", !0), 
        (0, e.default)(t, "fid", ""), t),
        _reset: function(t) {
            var a = this.data.olduserInfo;
            this.setData({
                isTouchScale: !1,
                hasScale: !1,
                hasRotate: !1,
                festivalCenterX: 0,
                festivalCenterY: 0,
                festivalLeft: 120,
                festivalTop: 120,
                offsetx: 0,
                offsety: 0,
                festivalSize: 80,
                oldx: 0,
                oldy: 0,
                startx: 0,
                starty: 0,
                initRotate: 0,
                rotate: 0,
                logoPath: null,
                userInfo: l({}, a)
            });
        },
        upimg: function() {
            wx.navigateTo({
                url: "/pages/cropple/cropple?type=2&id=" + this.data.fid
            });
        },
        chongzhi: function() {
            wx.showToast({
                title: "重置中...",
                icon: "loading",
                duration: 3e3,
                mask: !0
            }), this.data.festivalSrc = "../../images/tm.jpg", this.data.isSrc = !0, wx.setStorageSync("lock2", ""), 
            this.setData({
                currentHatId: "../../images/tm.jpg",
                yidong: !1,
                selId: -1
            }, function() {
                wx.hideToast();
            });
        },
        headimgHD: function(t) {
            return (t = t.split("/"))[t.length - 1] && 0 != t[t.length - 1] && (t[t.length - 1] = 0), 
            t.join("/");
        },
        handleLogin: function(t) {
            var a = this;
            wx.getUserProfile({
                desc: "用于完善会员资料",
                success: function(t) {
                    console.log(t.userInfo), wx.setStorageSync("userInfo", t.userInfo);
                    var e = a.headimgHD(t.userInfo.avatarUrl);
                    a.setData({
                        logoImg: e,
                        isLogin: !0,
                        modalName: !1
                    }), wx.setStorageSync("avatarUrlHD", e), wx.getImageInfo({
                        src: e,
                        success: function(t) {
                            wx.setStorageSync("avatarUrlHDTmp", t.path), a.data.logoPath = t.path, a.data.isLogo = !0;
                        }
                    });
                }
            });
        },
        _saveUserInfo: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null;
            if (t) {
                if (t.avatarUrl) {
                    t.avatarUrl = this.headimgHD(t.avatarUrl);
                    var a = t.avatarUrl;
                    this.setData({
                        logoImg: a,
                        isLogin: !0
                    });
                }
                this.setData({
                    userInfo: t
                }), r.globalData.userInfo = t;
            } else wx.showToast({
                title: "获取微信账号信息失败，请重新授权！",
                icon: "none"
            });
        },
        getIndexData: function() {
            var t = this;
            o.default.postRequest("/api/Index/pendant", {}, "加载中...", "loading", function(a) {
                t.setData({
                    loadingDH: !1
                }), 200 == a.data.status ? t.setData({
                    selId: a.data.data.pendant[0].id,
                    typeArr: a.data.data.pendant,
                    imgData: a.data.data.pendantImg
                }) : wx.showToast({
                    title: "请求失败",
                    icon: "none",
                    mask: !0,
                    duration: 1e3
                });
            }, function(t) {
                wx.showToast({
                    title: "请求失败",
                    icon: "none",
                    duration: 3e3
                });
            });
        },
        onShareAppMessage: function() {
            return wx.vibrateShort(), {
                title: "➜在线制作头像挂件边框小工具，点击开始制作",
                imageUrl: "https://www.daijingjuan.com/attachment/images/2.png",
                path: "/pages/index/index"
            };
        },
        onShareTimeline: function() {
            return {
                title: "➜在线制作头像挂件边框小工具，点击开始制作",
                query: "pages/index/index",
                imageUrl: "https://www.daijingjuan.com/attachment/images/2.png"
            };
        },
        onShow: function(t) {
            var a = wx.getStorageSync("userInfo");
            this.data.isLogo = !1, a ? (this.data.logoPath = wx.getStorageSync("avatarUrlHDTmp"), 
            this.data.isLogo = !0, this.data.isSrc = !0, this.setData({
                logoImg: wx.getStorageSync("avatarUrlHD"),
                isLogin: !0
            })) : (this.data.logoPath = wx.getStorageSync("avatarUrlHDTmp") ? wx.getStorageSync("avatarUrlHDTmp") : "../../static/image/default.jpeg", 
            this.data.isLogo = !0, this.data.isSrc = !0, this.setData({
                isLogin: !1,
                logoImg: wx.getStorageSync("avatarUrlHD") ? wx.getStorageSync("avatarUrlHD") : "../../static/image/default.jpeg"
            })), this.getImgData();
        },
        hideModal: function(t) {
            this.setData({
                modalName: !1
            });
        },
        onLoad: function(t) {
            console.log(t), t.id || wx.reLaunch({
                url: "/pages/home/home"
            }), this.data.fid = t.id, this.computeScrollViewHeight(), wx.setStorageSync("lock2", "");
        },
        computeScrollViewHeight: function() {
            var t = this;
            wx.createSelectorQuery().in(this).select(".userinfo").boundingClientRect(function(a) {
                var e = a.height, i = wx.getSystemInfoSync().windowHeight - e - 0;
                t.setData({
                    scrollHeight: i - r.globalData.CustomBar - 15 - 30
                });
            }).exec();
        },
        suo: function(t) {
            wx.showToast({
                title: "我是高级挂件哦~",
                icon: "none",
                duration: 800
            });
        },
        chooseImg: function(t) {
            console.log(t);
            var a = this, e = t.currentTarget.dataset.id;
            a.setData({
                yidong: !0,
                currentHatId: t.currentTarget.dataset.url,
                selId: t.currentTarget.dataset.index
            }), a.data.isSrc = !1, "lock" == t.currentTarget.dataset.item ? wx.setStorageSync("lock2", "lock") : wx.setStorageSync("lock2", "");
            var i = t.currentTarget.dataset.url;
            wx.getImageInfo({
                src: i,
                success: function(t) {
                    a.data.festivalSrc = t.path, a.data.isSrc = !0, o.default.postRequest("/api/Image/pendantClick", {
                        id: e
                    }, "", "", function(t) {
                        console.log(t);
                    }, function(t) {
                        wx.showToast({
                            title: "请求失败",
                            icon: "none",
                            duration: 3e3
                        });
                    });
                },
                fail: function(t) {}
            });
        },
        tabSelect: function(t) {
            var a = t.currentTarget.dataset.item;
            this.data.selId = a, this.setData({
                imgData: [],
                page: 1,
                TabCur: t.currentTarget.dataset.id,
                scrollLeft: 60 * (t.currentTarget.dataset.id - 1)
            }), this.getImgData();
        },
        scrollToLower: function(t) {
            wx.showToast({
                title: "加载中...",
                icon: "loading",
                mask: !0,
                duration: 3e3
            }), this.setData({
                page: this.data.page + 1
            }), this.getImgData(), wx.hideToast();
        },
        getImgData: function(t) {
            var a = this;
            o.default.postRequest("/api/Image/pendantDetail", {
                fid: a.data.fid,
                page: a.data.page
            }, "", "", function(t) {
                a.setData({
                    loadingDH: !1
                }), 200 == t.data.status ? a.setData({
                    imgData: a.data.imgData.concat(t.data.data)
                }) : wx.showToast({
                    title: "请求失败",
                    icon: "none",
                    mask: !0,
                    duration: 1e3
                });
            }, function(t) {
                wx.showToast({
                    title: "请求失败",
                    icon: "none",
                    duration: 3e3
                });
            });
        },
        setTab: function(t) {
            console.log(t);
            var a = t.currentTarget.dataset;
            this.setData({
                showtab: a.tabindex
            });
        },
        switchTab: function(t) {
            this.setData({
                currentTab: t.detail.current
            }), this.checkCor();
        },
        swichNav: function(t) {
            wx.vibrateShort();
            var a = t.currentTarget.dataset.id;
            this.data.currentTaB != a && (this.setData({
                currentTab: a
            }), this.getIndexData(a));
        },
        getUserInfo: function(t) {
            var a = t.detail.userInfo, e = void 0 === a ? null : a;
            null != e ? (r.globalData.userInfo = e, this._saveUserInfo(e)) : wx.showToast({
                title: t.detail.errMsg,
                icon: "none"
            });
        },
        onChangePickerFestival: function(t) {
            var a = this.data, e = a.icons, i = a.festivalNames, s = a.currentFestival, o = t.detail.value, n = i[o];
            e[s] = e[s].map(function(t, a) {
                return t.isselected = 0 == a, t;
            }), this.setData({
                festivalIndex: o,
                festivalImageIndex: 0,
                currentFestival: n,
                festivalSrc: e[n][0].src,
                icons: e
            });
        },
        clickCancelOpenSetting: function(t) {
            this.setData({
                isOpenSetting: !1,
                callback: null
            });
        },
        handlerOpenSetting: function(t) {
            if (1 == t.detail.authSetting["scope.writePhotosAlbum"]) {
                var a = this.data.callback, e = void 0 === a ? null : a;
                e && e(!0), this.setData({
                    isOpenSetting: !1,
                    callback: null
                });
            }
        },
        clickChangeAvatarImage: function(t) {
            var a = this;
            wx.chooseImage({
                count: 1,
                sizeType: [ "original", "compressed" ],
                sourceType: [ "album", "camera" ],
                success: function(t) {
                    var e = a.data.userInfo;
                    t.tempFilePaths.length > 0 ? (s.default.addObserver(a, "cutimagenotify", function(t) {
                        null != t ? (e.highAvatarUrl = t, e.avatarUrl = t, a.setData({
                            logoPath: t,
                            userInfo: e
                        })) : wx.showToast({
                            title: "请选择高清图像尺寸至少200x200以上！",
                            icon: "none"
                        });
                    }), wx.navigateTo({
                        url: "../edit/edit?imageurl=".concat(t.tempFilePaths[0])
                    })) : wx.showToast({
                        title: t.errMsg,
                        icon: "none"
                    });
                }
            });
        },
        _checkPhotosAlbum: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null, a = this;
            wx.getSetting({
                success: function(e) {
                    e.authSetting["scope.writePhotosAlbum"] ? (console.log("1-已经授权《保存图片》权限"), t && t(!0)) : wx.authorize({
                        scope: "scope.writePhotosAlbum",
                        success: function() {
                            t && t(!0);
                        },
                        fail: function() {
                            console.log("2-授权《保存图片》权限失败"), a.setData({
                                callback: t,
                                isOpenSetting: !0
                            });
                        }
                    });
                },
                fail: function(t) {
                    console.log("getSetting: success"), console.log(t);
                }
            });
        },
        clickMakeResetImage: function(t) {
            this._reset();
        },
        clickMakePoster: function(t) {
            this.data.makePosterImage = !0, this.clickMakeNewImage(t);
        },
        clickFestivalImage: function(t) {
            if (!this.data.loading) {
                var a = t.currentTarget.dataset.index, e = this.data, i = e.icons, s = e.currentFestival;
                i[s] = i[s].map(function(t, e) {
                    return t.isselected = e == a, t;
                }), this.setData({
                    icons: i,
                    festivalImageIndex: a,
                    festivalSrc: i[s][a].src
                });
            }
        },
        clickMakeNewImage: function(t) {
            var a = this;
            wx.vibrateShort(), this.data.isSrc && this.data.isLogo ? (wx.showToast({
                title: "生成中...",
                icon: "loading",
                duration: 3e3,
                mask: !0
            }), null == this.data.logoPath ? wx.downloadFile({
                url: this.data.userInfo.avatarUrl,
                success: function(t) {
                    a.data.logoPath = t.tempFilePath, a._saveImage();
                },
                fail: function(t) {
                    a.data.loading = !1, wx.showToast({
                        title: "获取微信图像失败",
                        icon: "none"
                    });
                }
            }) : this._saveImage()) : wx.showToast({
                title: "请稍候...",
                icon: "loading",
                duration: 1e3
            });
        },
        _saveImage: function() {
            var t = this.data, a = (t.makePosterImage, t.festivalLeft), e = t.festivalTop, s = t.festivalSize, o = t.festivalSrc, n = void 0 === o ? "" : o, l = t.rotate, r = t.logoPath, c = void 0 === r ? "" : r;
            if (t.festivalIndex, "" != n && "" != c) {
                var d = new i.default(this, "festivalCanvas", 700, 700);
                d.addImage({
                    path: c,
                    x: 0,
                    y: 0,
                    w: 700,
                    h: 700
                });
                var h = d.switchRect({
                    x: a,
                    y: e - 15,
                    w: s,
                    h: s
                });
                d.addImage({
                    path: n,
                    x: h.x,
                    y: h.y,
                    w: h.w,
                    h: h.h,
                    deg: l
                }), setTimeout(function() {
                    d.startCompound(function(t) {
                        console.log(t), wx.hideToast(), t ? (wx.setStorageSync("img_zhizuo", t), wx.navigateTo({
                            url: "../save/save?type=2"
                        })) : wx.showToast({
                            title: "图像生成失败~",
                            icon: "none",
                            duration: 1e3
                        });
                    });
                }, 100);
            } else wx.showToast({
                title: "程序异常，请联系作者",
                icon: "none"
            });
        },
        _getCurrentPointXiangxian: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0, a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, e = this.data, i = e.festivalCenterX, s = void 0 === i ? 0 : i, o = e.festivalCenterY, n = void 0 === o ? 0 : o;
            return t >= s && a <= n ? 1 : t <= s && a <= n ? 2 : t <= s && a >= n ? 3 : t >= s && a >= n ? 4 : void 0;
        },
        _switchPoint: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0, a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, e = this._getCurrentPointXiangxian(t, a), i = this.data, s = i.festivalCenterX, o = i.festivalCenterY;
            switch (e) {
              case 1:
              case 2:
              case 3:
              case 4:
                return {
                    x: t - s,
                    y: o - a
                };

              default:
                return null;
            }
        },
        _handlefestivalImageMoveScale: function(t) {
            if (t.touches.length > 0) {
                var a = this.data, e = a.oldx, i = void 0 === e ? 0 : e, s = a.oldy, o = void 0 === s ? 0 : s, n = a.festivalCenterX, l = void 0 === n ? 0 : n, r = a.festivalCenterY, c = void 0 === r ? 0 : r, d = (a.startx, 
                a.starty, a.initRotate, a.hasRotate), h = a.hasScale, u = a.offsety, f = a.offsetx, g = a.rotate, v = t.touches[0].pageX, p = t.touches[0].pageY;
                if (d || h) {
                    var m = Math.sqrt(Math.pow(Math.abs(v - l), 2) + Math.pow(Math.abs(p - c), 2)), w = Math.sqrt(Math.pow(Math.abs(i - l), 2) + Math.pow(Math.abs(o - c), 2)), x = Math.sqrt(Math.pow(Math.abs(i - v), 2) + Math.pow(Math.abs(o - p), 2)), S = (Math.pow(m, 2) + Math.pow(w, 2) - Math.pow(x, 2)) / (2 * m * w), I = Math.abs(Math.acos(S) / (Math.PI / 180)), T = this._switchPoint(i, o), y = this._switchPoint(v, p), D = T.x * y.y - T.y * y.x, b = Math.sqrt(Math.pow(2 * m, 2) / 2);
                    if (0 != D) {
                        var C = D < 0;
                        this.setData({
                            festivalTop: c - b / 2,
                            festivalLeft: l - b / 2,
                            festivalSize: b,
                            rotate: g + (C ? I : -I),
                            oldx: v,
                            oldy: p
                        });
                    } else this.setData({
                        festivalTop: c - b / 2,
                        festivalLeft: l - b / 2,
                        festivalSize: b,
                        oldx: v,
                        oldy: p
                    });
                } else this.setData({
                    festivalTop: p - u,
                    festivalLeft: v - f,
                    oldx: v,
                    oldy: p
                });
            }
        },
        festivalImageTouchStart: function(t) {
            if (!this.data.isTouchScale) {
                var a = this.data, e = (a.festivalLeft, a.festivalTop, a.festivalSize, t.touches[0].pageX), i = t.touches[0].pageY;
                this.data.startx = e, this.data.starty = i, this.data.oldx = e, this.data.oldy = i, 
                this.data.festivalCenterX = this.data.festivalLeft + this.data.festivalSize / 2, 
                this.data.festivalCenterY = this.data.festivalTop + this.data.festivalSize / 2, 
                this.data.hasRotate = !1, this.data.hasScale = !1, this.data.offsetx = e - this.data.festivalLeft, 
                this.data.offsety = i - this.data.festivalTop;
            }
        },
        festivalImageTouchMove: function(t) {
            this.data.isTouchScale || this._handlefestivalImageMoveScale(t);
        },
        festivalImageTouchEnd: function(t) {
            this.data.isTouchScale || this._handlefestivalImageMoveScale(t);
        },
        festivalImageRaoteTouchStart: function(t) {
            this.data.isTouchScale = !0, this.data.initRotate = this.data.rotate;
            var a = t.touches[0].pageX, e = t.touches[0].pageY;
            this.data.startx = a, this.data.starty = e, this.data.oldx = a, this.data.oldy = e, 
            this.data.festivalCenterX = this.data.festivalLeft + this.data.festivalSize / 2, 
            this.data.festivalCenterY = this.data.festivalTop + this.data.festivalSize / 2, 
            this.data.hasRotate = !0, this.data.hasScale = !0, this.data.offsetx = a - this.data.festivalLeft, 
            this.data.offsety = e - this.data.festivalTop;
        },
        festivalImageRaoteTouchMove: function(t) {
            this._handlefestivalImageMoveScale(t);
        },
        festivalImageRaoteTouchEnd: function(t) {
            this._handlefestivalImageMoveScale(t), this.data.isTouchScale = !1;
        }
    });
}();